from pydantic import BaseModel, Field
# from langchain_deepseek import ChatDeepSeek
from typing import Optional

from langchain_ollama import ChatOllama
llm = ChatOllama(model="qwen3:8b", temperature=0.5, reasoning=False)

# 定义Pydantic模型
class ProductInfo(BaseModel):
    """产品基本信息"""
    
    name: str = Field(description="产品名称")
    price: float = Field(description="产品价格，单位为元")
    category: str = Field(description="产品所属类别")
    rating: Optional[int] = Field(
        default=None, description="产品评分，1-10分"
    )

# 初始化模型
# llm = ChatDeepSeek(model="deepseek-chat")
structured_llm = llm.with_structured_output(ProductInfo)

# 调用示例
result = structured_llm.invoke("帮我分析一下iPhone 15这款手机")
print(result)
# 输出: ProductInfo(name='iPhone 15', price=5999.0, category='智能手机', rating=9)